/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kaytto1;

import com.sun.lwuit.Component;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.layouts.BoxLayout;
import java.io.IOException;

/**
 *
 * @author Joteitti
 */
public class HomeForm extends Form {

    public static final String DEFAULT_LOGO = "/logo.png";

    private HomeService homeService;
    private Label logoLabel;
    private TextArea descriptionTextArea;
    private TextArea instructionTextArea;

    public HomeForm(HomeService homeService) {
        super();

        // Set home service
        this.homeService = homeService;

        // Create form layout and components
        setTitle(Text.getString(Text.TEXT_HOME_TITLE));
        addCommandListener(homeService);
        addCommand(homeService.getStartCommand());
        addCommand(homeService.getExitCommand());
        setTransitionOutAnimator(homeService.getTransition());
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        addComponent(getLogoLabel());
        addComponent(getDescriptionTextArea());
        addComponent(getInstructionTextArea());
    }

    private Label getLogoLabel() {
        // Lazy initialization
        if(logoLabel == null) {
            try {
                logoLabel = new Label(Image.createImage(DEFAULT_LOGO));
                logoLabel.setAlignment(Component.CENTER);
            } catch (IOException e) {
                homeService.showExitDialog(e.getMessage(), e.toString());
            }
        }

        return logoLabel;
    }

    private TextArea getDescriptionTextArea() {
        // Lazy initialization
        if(descriptionTextArea == null) {
            descriptionTextArea = new TextArea(Text.getString(Text.TEXT_HOME_DESCRIPTION));
            descriptionTextArea.setConstraint(TextArea.UNEDITABLE );
            descriptionTextArea.setEditable(false);
            descriptionTextArea.setFocusPainted(false);
        }

        return descriptionTextArea;
    }

    private TextArea getInstructionTextArea() {
        // Lazy initialization
        if(instructionTextArea == null) {
            instructionTextArea = new TextArea(Text.getString(Text.TEXT_HOME_INSTRUCTION));
            instructionTextArea.setConstraint(TextArea.UNEDITABLE );
            instructionTextArea.setEditable(false);
            instructionTextArea.setFocusPainted(false);
        }

        return instructionTextArea;
    }
}
